package cn.tedu.controller;

import cn.tedu.pojo.Car;
import cn.tedu.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("car")
public class CarController {
    @Autowired //DI 绑定两者的关系：即控制层（类）与业务层（接口）的关系
    private CarService carService;

    @RequestMapping("get")
    public List<Car> get(){
        return carService.get();
    }
    //新增业务
    //http://localhost:8080/car/add?id=10&name=BSJ&color=gray&price=10
    @RequestMapping("add")
    public  void add(Car c){//传参
        System.out.println(c);//Car(id=10, name=BSJ, color=gray, price=10.0)
        carService.add(c);//传参；调用add方法，不用返回前端页面。过程：从前端传到后端再到数据库做新增
    }
}
